<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      :data="courseList"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import { getCourseList } from "../../../api/course";

export default {
  data() {
    return {
      filterText: '',
      courseList: [],
      defaultProps: {
        children: 'children',
        label: 'categoryName'
      }
    }
  },

  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
created () {
  getCourseList('http://localhost:8080/course-web/coursecategory/.jsonp?page=1&limit=100').then((res) => {
    this.courseList = res.content
  })
},

  methods: {
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
  }
}
</script>

